package com.jh.complicate.serializable;

/**
 * @author Administrator
 * @projectName newforward
 * @title SerializeTest.java
 * @package com.jh.complicate.serializable
 * @description 序列化测试
 * @date 2019/6/4 23:00
 */
public class SerializeTest {
    public static void main(String[] args) {

        // Java原生序列化
        //ISerializable serializer = new JavaSerializer();

        // 文件序列化
        //ISerializable serializer = new FileSerializer();

        // XML序列化
        //ISerializable serializer = new XStreamSerializer();

        // JSON序列化
        // FastJson序列化不能通过writeObject和readObject去绕过Transient关键字，如果有这个关键字的属性就不会被序列化
        //ISerializable serializer = new FastJsonSerializer();

        // Hessian
        ISerializable serializer = new HessianSerializer();

        User user = new User();
        user.setAge(1);
        user.setName("JH");

        byte[] data = serializer.serialize(user);
        System.out.println("byte length：" + data.length);
        System.out.println(new String(data));

        User tmp = serializer.deserialize(data, User.class);
        System.out.println(tmp.toString());
    }
}
